package com.heima.home.mapper;

import com.heima.home.dto.ReviewsDTO;
import com.heima.home.entity.Reviews;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Delete;

import java.util.List;

@Mapper
public interface ReviewsMapper {

    @Insert("insert into reviews(booking_id,user_id,property_id,host_id,rating,content,cleanliness_rating,value_rating,check_in_rating,created_at,updated_at)" +
            " values(#{bookingId},#{userId},#{propertyId},#{hostId},#{rating},#{content},#{cleanlinessRating},#{valueRating},#{checkInRating},#{createdAt},#{updatedAt})")
    int addReviews(ReviewsDTO reviewsDTO);

    @Select("select * from reviews where user_id=#{userId} order by created_at desc")
    List<ReviewsDTO> showAllReviewsByUserId(Integer userId);
    
    @Select("select * from reviews where id=#{id}")
    Reviews findById(Integer id);
    
    @Delete("delete from reviews where id=#{id}")
    boolean deleteReviews(Integer id);
    
    @Update("update reviews set rating=#{rating}, content=#{content}, " +
            "cleanliness_rating=#{cleanlinessRating}, value_rating=#{valueRating}, " +
            "check_in_rating=#{checkInRating}, updated_at=#{updatedAt} where id=#{id}")
    boolean updateReviews(ReviewsDTO reviewsDTO);

    @Select("select * from reviews where property_id= #{propertyId}")
    List<ReviewsDTO> findByPropertyId(Integer propertyId);
    
    @Select("select count(*) from reviews where user_id = #{userId}")
    Integer countByUserId(Integer userId);

}